package com.cloud.log.autolevel.config;


import com.cloud.log.autolevel.service.LogLevelSettingService;
import com.cloud.log.autolevel.service.impl.LogLevelSettingServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: ZhangKaiQiang
 * @date: 2021/1/4
 * @time: 17:57
 **/
@Configuration
@ConditionalOnProperty(prefix = "auto.level", name = "enable", havingValue = "true")
public class AutoLevelConfig {

    private final LoggingSystem loggingSystem;

    @Autowired
    public AutoLevelConfig(LoggingSystem loggingSystem){
        this.loggingSystem=loggingSystem;
    }

    @Bean
    @ConditionalOnMissingBean
    public LogLevelSettingService loggerLevelSettingService() {
        return new LogLevelSettingServiceImpl(loggingSystem);
    }
}
